package com.enjoyor.soa.traffic.server.efoms.dubbo.invoke;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.service.dubbo.CallbackListener;
import com.enjoyor.soa.traffic.api.service.dubbo.efoms.CallBackService;

@Component
public class DubboPingCallBackInvoke {

	@Reference(version = "1.0.0", timeout = 10000)
    private CallBackService callBackService;

    /**
	 * 向回调服务中注册一个监听器
	 * 如果有历史监听，则覆盖
	 * @param listener 监听器
	 */
	public String addListener(String key, CallbackListener listener){
		String str = null;
		if (null != callBackService) {
			str = callBackService.addListener(key, listener);
        }
        return str;
    }
	
	/**
	 * 移除监听
	 * @param key
	 * @return
	 */
	public Boolean removeListener(String key) {
		Boolean flag = false;
		if (null != callBackService) {
			flag = callBackService.removeListener(key);
        }
		return flag;
	}
	/**
	 * 返回回调服务目前的状态，以判定其工作是否正常
	 * @return 0：表明回调服务工作正常，其他：表明回调服务无法正常工作
	 */
	public boolean isActive(String key) {
		Boolean flag = false;
		if (null != callBackService) {
			flag = callBackService.isActive(key);
        }
		return flag;
	}
}
